import Mock from 'mockjs'

Mock.mock('/mock/login', 'post', (req: any) => {
    const { username, password } = JSON.parse(req.body)
    
    // 模拟账号密码验证
    const mockUsers = [
        { username: 'admin', password: '123456', role: 'admin' },
        { username: 'doctor', password: 'doctor123', role: 'doctor' },
        { username: 'patient', password: 'patient123', role: 'patient' },
        { username: 'test', password: 'test123', role: 'user' }
    ]
    
    const user = mockUsers.find(u => u.username === username && u.password === password)
    
    if (user) {
        return {
            code: 200,
            message: '登录成功',
            data: {
                token: 'mock_token_' + Date.now(),
                userInfo: {
                    id: Math.floor(Math.random() * 1000),
                    username: user.username,
                    role: user.role,
                    avatar: 'https://via.placeholder.com/100',
                    nickname: user.username === 'admin' ? '管理员' : 
                              user.username === 'doctor' ? '医生' : 
                              user.username === 'patient' ? '患者' : '用户'
                }
            }
        }
    } else {
        return {
            code: 401,
            message: '用户名或密码错误',
            data: null
        }
    }
})

// 模拟订单列表数据
Mock.mock('/mock/orders', 'get', () => {
    const orders = [
        {
            orderNo: '202412150001',
            status: '已完成',
            amount: 150.00,
            createTime: '2024-12-15 10:30:00',
            doctorName: '张医生',
            department: '内科',
            hospitalName: '新冠预防',
            patientName: '李某某',
            serviceType: '在线问诊',
            paymentMethod: '微信支付'
        },
        {
            orderNo: '202412150002',
            status: '进行中',
            amount: 200.00,
            createTime: '2024-12-15 11:15:00',
            doctorName: '王医生',
            department: '外科',
            hospitalName: '北京协和医院',
            patientName: '张某某',
            serviceType: '视频问诊',
            paymentMethod: '支付宝'
        },
        {
            orderNo: '202412150003',
            status: '已取消',
            amount: 100.00,
            createTime: '2024-12-15 14:20:00',
            doctorName: '李医生',
            department: '儿科',
            hospitalName: '北京协和医院',
            patientName: '王某某',
            serviceType: '图文问诊',
            paymentMethod: '银行卡'
        },
        {
            orderNo: '202412150004',
            status: '待支付',
            amount: 180.00,
            createTime: '2024-12-15 16:45:00',
            doctorName: '赵医生',
            department: '妇科',
            hospitalName: '北京协和医院',
            patientName: '刘某某',
            serviceType: '电话问诊',
            paymentMethod: '微信支付'
        },
        {
            orderNo: '202412150005',
            status: '已完成',
            amount: 120.00,
            createTime: '2024-12-15 09:10:00',
            doctorName: '陈医生',
            department: '皮肤科',
            hospitalName: '北京协和医院',
            patientName: '陈某某',
            serviceType: '在线问诊',
            paymentMethod: '支付宝'
        }
    ]
    
    return {
        code: 200,
        message: '获取订单列表成功',
        data: {
            list: orders,
            total: orders.length,
            pageSize: 10,
            currentPage: 1
        }
    }
})

// 模拟订单详情数据
Mock.mock(/\/mock\/orders\/\d+/, 'get', (req: any) => {
    const orderId = req.url.split('/').pop()
    
    const orderDetail = {
        orderNo: '202412150001',
        status: '已完成',
        amount: 150.00,
        createTime: '2024-12-15 10:30:00',
        payTime: '2024-12-15 10:32:00',
        completeTime: '2024-12-15 11:00:00',
        doctorInfo: {
            name: '张医生',
            department: '内科',
            hospitalName: '北京协和医院',
            avatar: 'https://via.placeholder.com/80',
            title: '主任医师',
            experience: '20年临床经验',
            specialty: '心血管疾病、高血压、糖尿病'
        },
        patientInfo: {
            name: '李某某',
            age: 45,
            gender: '男',
            phone: '138****1234',
            idCard: '110101****1234'
        },
        serviceInfo: {
            type: '在线问诊',
            duration: '30分钟',
            description: '患者主诉胸闷气短，需要专业诊断'
        },
        paymentInfo: {
            method: '微信支付',
            transactionId: 'wx202412151030001',
            amount: 150.00,
            status: '已支付'
        },
        consultationRecord: {
            symptoms: '胸闷气短，活动后加重',
            diagnosis: '疑似冠心病，建议进一步检查',
            prescription: '阿司匹林 100mg 每日一次',
            advice: '注意休息，避免剧烈运动，定期复查'
        }
    }
    
    return {
        code: 200,
        message: '获取订单详情成功',
        data: orderDetail
    }
})